<template>
  <swiper
    :class="styles.swiper"
    indicator-color="#999"
    indicator-active-color="#48cfad"
    :circular="true"
    :indicator-dots="true"
  >
    <swiper-item>
      <div :class="styles.menu">
        <div
          @click="() => showMoreHandle(menu.id)"
          :class="styles.menuItem"
          v-for="(menu, index) in menuList.slice(0, 10)"
          :key="index"
        >
          <img :class="styles.menuItemImg" :src="menu.icon" alt="" />
          <div>{{ menu.name }}</div>
        </div>
      </div>
    </swiper-item>
  </swiper>
</template>

<script lang="ts">
import { onMounted, ref } from 'vue';
import Taro from '@tarojs/taro';
import { useResumeStore } from '@/stores';

import styles from './index.module.less';
import { ICategory } from '@/types';

export default {
  setup() {
    const menuList = ref<ICategory[]>([]);
    const resumeStore = useResumeStore();
    onMounted(async () => {
      menuList.value = await resumeStore.getCategoryList();
    });

    const showMoreHandle = (categoryId) => {
      Taro.navigateTo({
        url: `/subpackages/commodity-list/index?categoryId=${categoryId}`,
      });
    };

    return {
      menuList,
      styles,
      showMoreHandle,
    };
  },
};
</script>
